<?php

namespace app\admin\controller;

class Index extends Common {

        public function _initialize() {
                $this->checkUser();
        }

        public function index() {
		$uid = get_member_id();
		$map = array(
		    'menu' => 1,
		    'status' => 1,
		);
		if ($uid != 1) {
			$Auth = new \org\Auth();
			$groups = $Auth->getGroups($uid);
			if (!empty($groups)) {
				$ids = array(); //保存用户所属用户组设置的所有权限规则id
				foreach ($groups as $g) {
					$ids = array_merge($ids, explode(',', trim($g['rules'], ',')));
				}
				$ids = array_unique($ids);
				$map['id'] = array('in', $ids);
			} else {
				$map['id'] = 0;
			}
		}

		//读取用户组所有权限规则
		$rules = M("AuthRule")->where($map)->field('id,pid,name,title,group')->order('sort desc')->select();
		$menu = array();
		foreach ($rules as $value) {
			$menu[$value['group']][] = $value;
		}
		$menu = array_values($menu);
		session('menu' . $uid, $menu);
		$this->assign("menu", $menu);
		$this->assign("nav", array_shift($menu));
                
                //线路总数
		$lineModel = M("Tours");
		$lineCount = $lineModel->count();
		$this->assign('lineCount', $lineCount);
                
                //订单总数
		$orderModel = M("ToursOrder");
		$orderCount = $orderModel->where(array('is_del'=>0))->count();
		$this->assign('orderCount', $orderCount);
                //询单总数
		$zixunModel = M("ToursCounsel");
		$zixunCount = $zixunModel->where(array('reply'=>''))->count();
		$this->assign('zixunCount', $zixunCount);
                //文章总数
		$newsModel = M("News");
		$newsCount = $newsModel->count();
		$this->assign('newsCount', $newsCount);
                
                $mid = get_member_id();

		$condition['mid'] = $mid;
		$condition['reply'] = '';
		$condition['_logic'] = 'OR';		
		$newCounsle = D("ToursCounsel")->relation(true)->where($condition)->order("create_time desc")->limit(5)->select();
		$this->assign('newZixun', $newCounsle);
                /*
		 * 最新订单
		 */
                
		$maps['status'] = 0;   
                $maps['is_del'] = 0;
		$newOrder = D("ToursOrder")->relation(true)->where($maps)->order("create_time desc")->limit(5)->select();
		$this->assign('newOrder', $newOrder);
                return $this->fetch();
	}



}
